// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

import Hero from "./hero";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Skillboard extends cc.Component {

  @property(Hero)
  hero: Hero = null;

  @property(cc.Node)
  private btnAcc: cc.Node = null;

  @property(cc.Node)
  private btnRotate: cc.Node = null;

  @property(cc.Node)
  private mask: cc.Node = null;

  private speed = 82 / 5;
  private startChange = false;

  onLoad() {
    this.btnAcc.on(cc.Node.EventType.TOUCH_START, () => {
      this.hero.accelerate();
    })
    this.btnAcc.on(cc.Node.EventType.TOUCH_END, () => {
      this.hero.speedToNormal();
    });
    this.btnAcc.on(cc.Node.EventType.TOUCH_CANCEL, () => {
      this.hero.speedToNormal();
    })
    this.btnRotate.on(cc.Node.EventType.TOUCH_START, () => {
      this.hero.rotateSkill();
      this.mask.height = 0;
      this.startChange = true;
    })
  }

  update(dt) {
    if (this.startChange) {
      this.mask.height = this.mask.height + this.speed * dt
      if (this.mask.height >= 82) {
        this.mask.height = 82;
        this.startChange = false;
      }
    }
  }
}
